package com.example.asus.my12306;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.example.asus.my12306.my.MyAccountActivity;
import com.example.asus.my12306.my.MyContactActivity;
import com.example.asus.my12306.my.MyPasswordActivity;

public class MainActivity extends Activity {

    Button btnLogout = null;
    ListView lvMyList = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d("My12306","---onCreate---");

        btnLogout = findViewById(R.id.btn_Logout);
        lvMyList = findViewById(R.id.lv_MyList);
        String[] data = getResources().getStringArray(R.array.my_list_data);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                MainActivity.this, android.R.layout.simple_list_item_1, data);
        lvMyList.setAdapter(adapter);
        lvMyList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                Intent intent = new Intent();

                switch (position) {
                    case 0:
                        intent.setClass(MainActivity.this, MyContactActivity.class);
                        break;
                    case 1:
                        intent.setClass(MainActivity.this, MyAccountActivity.class);
                        break;
                    case 2:
                        intent.setClass(MainActivity.this, MyPasswordActivity.class);
                        break;
                }
                startActivity(intent);
            }
        });

        MyButtonListener listener = new MyButtonListener();
        btnLogout.setOnClickListener(listener);

    }

    class MyButtonListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // 区分按钮
            Intent intent = new Intent();
            intent.setClass(MainActivity.this, LoginActivity.class);
            startActivity(intent);
            finish();
        }

    }

    @Override
    protected void onStart() {

        super.onStart();
        Log.d("My12306", "---onStart---");
    }

    @Override
    protected void onRestart() {

        super.onRestart();
        Log.d("My12306", "---onRestart---");
    }

    @Override
    protected void onPause() {

        super.onPause();
        Log.d("My12306", "---onPause---");
    }

    @Override
    protected void onResume() {

        super.onResume();
        Log.d("My12306", "---onResume---");
    }

    @Override
    protected void onStop() {

        super.onStop();
        Log.d("My12306", "---onStop---");
    }

    @Override
    protected void onDestroy() {

        super.onDestroy();
        Log.d("My12306", "---onDestroy---");
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {

        super.onSaveInstanceState(outState);
        Log.d("My12306", "---onSaveInstanceState---");
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {

        super.onRestoreInstanceState(savedInstanceState);
        Log.d("My12306", "---onRestoreInstanceState---");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}


